#include "ofxColorPicker.h"

void ofxColorPicker::grab(int x, int y) {
    img.grabScreen(x,y,1,1);

    int r = img.getPixels()[0];
    int g = img.getPixels()[1];
    int b = img.getPixels()[2];

    pixColor = ofxColor(r,g,b);
}

int ofxColorPicker::getRed() {
    return pixColor.red;
}

int ofxColorPicker::getGreen() {
    return pixColor.green;
}

int ofxColorPicker::getBlue() {
    return pixColor.blue;
}

string ofxColorPicker::getHexCode() {
    pixColor.alpha = 0; // ugly hack to get exactly 6 hex digits without alpha
    string returnValue;
    char outStr[256];
    sprintf(outStr,"%06x",pixColor.asHex(OF_COLOR_RGB));
    returnValue = outStr;
    return returnValue;
}

int ofxColorPicker::getHue() {
    return pixColor.hue;
}

int ofxColorPicker::getSaturation() {
    return pixColor.saturation;
}

int ofxColorPicker::getBrightness() {
    return pixColor.value;
}
